package com.test.ml.base;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.test.ml.yqs.entity.TqzTask;
import com.test.ml.yqs.utills.ResultJson;
import com.test.ml.yqs.vo.Page;
import org.codehaus.jackson.map.Serializers;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author 马亮
 * @version V1.0
 * @Description: TODO
 */
public abstract class BaseService<TDto extends BaseEntity, TMaper extends  BaseMapper> {

    @Autowired
    private TMaper maper;


    public ResultJson add(TDto task) {
        maper.insert(task);
        return ResultJson.buildSuccess("新增成功");
    }

    public  ResultJson update(TDto task){
        maper.update(task);
        return ResultJson.buildSuccess("修改成功");
    }

    public  ResultJson delete(String[] id){
        maper.deleteByIds(id);
        return ResultJson.buildSuccess("删除成功");
    }

    public  <TDto extends BaseEntity> ResultJson queryList(TDto entity, Page page){
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<TqzTask> tasks= maper.queryList(entity);
        PageInfo pageInfo = new PageInfo(tasks);
        return ResultJson.buildSuccess("查询成功",pageInfo);
    }
}